package com.jindi.appplan;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class CreateHtmlUtils {

    public static void main(String[] args) {
        String filePath = "F:\\project-repository\\yys\\src\\main\\java\\com\\jindi\\appplan\\tem.html";
        String imagePath ="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1546576839552&di=52a341d5a8b3ae4c23c9b020c2a4c0b3&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2018-11-26%2F5bfb63c83c665.jpg";
        String disrPath = "F:\\project-repository\\yys\\src\\main\\java\\com\\jindi\\appplan\\";
        String fileName = "liuren";
        MakeHtml(filePath,imagePath,disrPath,fileName);
    }
    /**
     * @Title: MakeHtml
     * @Description: 创建html
     * @param    filePath 设定模板文件
     * @param    imagePath 需要显示图片的路径
     * @param    disrPath  生成html的存放路径
     * @param    fileName  生成html名字
     * @return void    返回类型
     * @throws
     */
    public static void MakeHtml(String filePath,String imagePath,String disrPath,String fileName ){
        try {
            String title = "<image src="+'"'+imagePath+'"'+"/>";
            System.out.print(filePath);
            String templateContent = "";
            FileInputStream fileinputstream = new FileInputStream(filePath);// 读取模板文件
            int lenght = fileinputstream.available();
            byte bytes[] = new byte[lenght];
            fileinputstream.read(bytes);
            fileinputstream.close();
            templateContent = new String(bytes);
            System.out.print(templateContent);
            templateContent = templateContent.replaceAll("content_text", "小龙AutoCAD病毒专杀,AutoCAD病毒专杀,AutoCAD专杀,AutoCAD病毒专杀工具").replaceAll("titt","小龙AutoCAD杀毒v2.8.1.18下载 - 杀毒软件 - 非凡软件站");
            System.out.print(templateContent);

            String fileame = fileName + ".html";
            fileame = disrPath+"/" + fileame;// 生成的html文件保存路径。
            FileOutputStream fileoutputstream = new FileOutputStream(fileame);// 建立文件输出流
            System.out.print("文件输出路径:");
            System.out.print(fileame);
            byte tag_bytes[] = templateContent.getBytes();
            fileoutputstream.write(tag_bytes);
            fileoutputstream.close();
        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}
